define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'technician/check_user/index' + location.search,
                    // add_url: 'technician/check_user/add',
                    edit_url: 'technician/check_user/edit',
                    del_url: 'technician/check_user/del',
                    multi_url: 'technician/check_user/multi',
                    import_url: 'technician/check_user/import',
                    table: 'check_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'idno', title: __('Idno'), operate: 'LIKE'},
                        {field: 'identity_positive', title: __('Identity_positive'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'identity_reverse', title: __('Identity_reverse'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'photo', title: __('Photo'), operate: 'LIKE',events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'ajax',
                                text: __('同意'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                url: 'technician/check_user/agree',
                                confirm: '确认同意吗?',
                                disable: function(row) {
                                    if (row.status!=3) {
                                        return true;
                                    }
                                    return false;
                                },
                                success: function(data, ret) {
                                    Layer.alert(ret.msg);
                                    $(".btn-refresh").click();//刷新列表
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function(data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    $(".btn-refresh").click();//刷新列表
                                    return false;
                                }
                            },
                                {
                                    name: 'ajax',
                                    text: __('拒绝'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    url: 'technician/check_user/disAgree',
                                    confirm: '确认拒绝吗?',
                                    disable: function(row) {
                                        if (row.status !=3) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    success: function(data, ret) {
                                        Layer.alert(ret.msg);
                                        $(".btn-refresh").click();//刷新列表
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function(data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        $(".btn-refresh").click();//刷新列表
                                        return false;
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
